//
//  NavgationView.m
//  qunfa
//
//  Created by Admin on 2017/8/10.
//  Copyright © 2017年 cuixiaocun. All rights reserved.
//

#import "NavgationView.h"

@implementation NavgationView
- (id)initWithFrame:(CGRect)frame with:(NSString *)navName isBackBtn:(NSString *)isBackBtn rightBtnName:(NSString *)btnString
{
    if ( self= [super initWithFrame:frame]) {
        //替代导航栏的imageview
        UIImageView *topImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CXCWidth, 64)];
        topImageView.userInteractionEnabled = YES;
        topImageView.backgroundColor = [UIColor whiteColor];
        [self addSubview:topImageView];
        if ([isBackBtn isEqualToString:@"YES"]) {
            //添加返回按钮
            UIButton *  returnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            returnBtn.frame = CGRectMake(0, 20, 44, 44);
            [returnBtn setImage:[UIImage imageNamed:navBackarrow] forState:UIControlStateNormal];
            [returnBtn addTarget:self action:@selector(returnBtnAction) forControlEvents:UIControlEventTouchUpInside];
            [topImageView addSubview:returnBtn];
   
        }
        //注册标签
        _navLabel =[[UILabel alloc] initWithFrame:CGRectMake(100*Width, 20, 550*Width, 44)];
        [_navLabel setText:[NSString stringWithFormat:@"%@",navName]];
        [_navLabel setTextAlignment:NSTextAlignmentCenter];
        [_navLabel setBackgroundColor:[UIColor clearColor]];
        [_navLabel setFont:[UIFont boldSystemFontOfSize:18]];
        [_navLabel setNumberOfLines:0];
        [_navLabel setTextColor:[UIColor blackColor]];
        [self addSubview:_navLabel];
        
        if (![btnString isEqualToString:@"NO"]) {
        //授权
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightBtn.frame = CGRectMake(CXCWidth-60, 20, 44, 44);
        _rightBtn.titleLabel.font =[UIFont boldSystemFontOfSize:15];
        [_rightBtn setTitle:[NSString stringWithFormat:@"%@",btnString] forState:UIControlStateNormal];
        [_rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [topImageView addSubview:_rightBtn];
        }
        
    }
    return self;
}
-(void)returnBtnAction
{
    [_delegate retunButtonAction];

   
}
- (void)rightBtnAction
{
    
    [_delegate rightButtonAction];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
